package com.jp.knowledge.fragment;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;

import com.jp.knowledge.activity.JpApplicationWebActivity;
import com.jp.knowledge.adapter.SearchRecommentAdapter;
import com.jp.knowledge.broad.LocalBroadCast;
import com.jp.knowledge.model.HeadLineData;
import com.jp.knowledge.model.ProductUIModel;
import com.jp.knowledge.my.base.RecycleVAdapter;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/2/23.
 */

public class CollectionRecommendFragment extends CollectionNewsFragment {

    @Override
    protected RecyclerView.Adapter initAdapter(final List datas) {
        final SearchRecommentAdapter adapter = new SearchRecommentAdapter(mContext, datas);
        adapter.setType(label);
        adapter.addItemClickListener(new RecycleVAdapter.OnItemClickListener() {
            @Override
            public void itemSelect(int position) {
                onItemClick(position);
            }
        });
        adapter.setCollectionCallback(new SearchRecommentAdapter.CollectionCallback() {
            @Override
            public void onCollection(int position, String id, boolean isCollection, boolean isSuccess) {
                if(isSuccess && !isCollection){
                    itemDelete(position);
                }
            }
        });
        return adapter;
    }

    @Override
    protected void onItemClick(int position){
        JpApplicationWebActivity.gotoWebActivity(mContext,
                "details/recommendDetail?id=" + ((HeadLineData)datas.get(position)).getId() + "&source=kengPo");
    }

    @Override
    protected void onBroadCastReceive(String action, Intent intent){
        if(!LocalBroadCast.COMM_CHANGE_SIZE.equals(action))
            super.onBroadCastReceive(action, intent);
    }
}
